package com.yutian.example.demo.forum.dao;

import com.yutian.example.demo.forum.dao.model.Topic;
import com.yutian.example.demo.forum.dao.model.req.TopicPageReqDO;
import com.yutian.example.demo.forum.dao.model.rsp.TopicPageRspDO;
import com.yutian.example.demo.forum.mapper.TopicMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class TopicDAO {

    // 原理：mybatis-spring-boot-starter，
    // springboot启动时，帮我们自动生成SqlSessionFactory和SqlSession，
    // 并扫描@Mapper，创建TopicMapper实现类对象实例topicMapper
    @Autowired
    private TopicMapper topicMapper;

    public Topic get(Long id){
        return topicMapper.get(id);
    }

    public List<Topic> list(String titleLike){
        return topicMapper.list(titleLike);
    }

    public long insert(Topic topic){
        return topicMapper.insert(topic);
    }

    public List<Topic> listByIds(List<Long> ids){
        return topicMapper.listByIds(ids);
    }

    public long count(TopicPageReqDO req){
        return topicMapper.count(req);
    }

    public List<TopicPageRspDO> page(TopicPageReqDO req){
        return topicMapper.page(req);
    }
}